package cn.iocoder.yudao.module.erp.dal.mysql.relationship;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.relationship.vo.RelationshipPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.relationship.vo.RelationshipRespVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.relationship.RelationshipDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 物料供应商关联 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface RelationshipMapper extends BaseMapperX<RelationshipDO> {

    default PageResult<RelationshipDO> selectPage(RelationshipPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RelationshipDO>()
                .likeIfPresent(RelationshipDO::getProductId, String.valueOf(reqVO.getProductId()))
                .likeIfPresent(RelationshipDO::getSupplierId, String.valueOf(reqVO.getSupplierId()))
                .betweenIfPresent(RelationshipDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RelationshipDO::getId));
    }


    @Delete("delete  from erp_relationship where product_id = " + "#{id}")
    void deleteByList(Long id);

    @Select("select * from erp_relationship where product_id =" + "#{id}")
    List<String> selectBySupplierId(Long id);

    @Select("select supplier_id,sort from erp_relationship where  product_id = " + "#{id}")
    List<RelationshipRespVO> getSupplie(Long id);

    default List<RelationshipDO> selectByProductId(Long productId) {
        return selectList(RelationshipDO::getProductId, productId);
    }

    default List<RelationshipDO> selectByProductIds(List<Long> productIds) {
        return selectList(RelationshipDO::getProductId, productIds);
    }
}